package com.micro.school.system.service.impl;

import com.micro.school.system.domain.CampusUser;
import com.micro.school.system.mapper.CampusUserMapper;
import com.micro.school.system.service.CampusUserService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import java.util.List;

/**
 * 登录账号对应校区(CampusUser)表服务实现类
 *
 * @author makejava
 * @since 2025-08-09 13:55:33
 */
@Service("campusUserService")
public class CampusUserServiceImpl implements CampusUserService {
    @Resource
    private CampusUserMapper campusUserMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public CampusUser queryById(Long userId,String tenantId) {
        return this.campusUserMapper.queryById(userId,tenantId);
    }

    @Override
    public CampusUser queryByUserId(Long userId) {
        return this.campusUserMapper.queryByUserId(userId);
    }

    /**
     * 分页查询
     *
     * @param campusUser 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<CampusUser> queryByPage(CampusUser campusUser, PageRequest pageRequest) {
        long total = this.campusUserMapper.count(campusUser);
        return new PageImpl<>(this.campusUserMapper.queryAllByLimit(campusUser, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param campusUser 实例对象
     * @return 实例对象
     */
    @Override
    public CampusUser insert(CampusUser campusUser) {
        this.campusUserMapper.insert(campusUser);
        return campusUser;
    }

    /**
     * 修改数据
     *
     * @param campusUser 实例对象
     * @return 实例对象
     */
    @Override
    public void update(CampusUser campusUser) {
        this.campusUserMapper.update(campusUser);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.campusUserMapper.deleteById(id) > 0;
    }
}
